(function () {
  var r = new RegExp("(^|(.*?\\/))(index.js)(\\?|$)"),
    s = document.getElementsByTagName("script"),
    targetScript;
  for (var i = 0; i < s.length; i++) {
    var src = s[i].getAttribute("src");
    if (src) {
      var m = src.match(r);
      if (m) {
        targetScript = s[i];
        break;
      }
    }
  }
  var cssExpr = new RegExp("\\.css");
  function inputLibs(list) {
    if (list == null || list.length === 0) {
      return;
    }
    for (var i = 0, len = list.length; i < len; i++) {
      var url = list[i];
      if (cssExpr.test(url)) {
        var css = '<link rel="stylesheet" href="' + url + '">';
        document.writeln(css);
      } else {
        var script =
          '<script type="text/javascript" src="' + url + '"><' + "/script>";
        document.writeln(script);
      }
    }
  }
  function load() {
    var arrInclude = (targetScript.getAttribute("include") || "").split(",");
    var libpath = targetScript.getAttribute("libpath") || "";
    if (libpath.lastIndexOf("/") !== libpath.length - 1) {
      libpath += "/";
    }
    // 版本兼容
    var libsConfig = {
      files: [
        libpath + "Cesium/Widgets/widgets.css",
        libpath + "Cesium/Cesium.js",
        libpath + "dat.gui.min.js",
      ],
    };
    var keys = {};
    for (var i = 0, len = arrInclude.length; i < len; i++) {
      var key = arrInclude[i];
      if (keys[key]) {
        //规避lib重复
        continue;
      }
      keys[key] = true;
      inputLibs(libsConfig[key]);
    }
  }
  load();
})();
